/**
 * 
 */
package org.vectrics.cv;

import org.vectrics.common.db.RecordObject;
import org.vectrics.common.util.StringUtils;
import org.vectrics.user.Person;

/**
 * @author gvilla
 * 
 */
public class ExtraCertificate implements RecordObject, Comparable<ExtraCertificate> {

    Long id;

    Person person;

    String name;

    public ExtraCertificate() {

    }

    public ExtraCertificate(final String code, final String certName) {
        name = code + " - " + certName;
    }

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(final Long id) {
        this.id = id;
    }

    /**
     * @param name
     *            the name to set
     */
    public void setName(final String name) {
        this.name = name;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Comparable#compareTo(java.lang.Object)
     */
    @Override
    public int compareTo(final ExtraCertificate o) {
        return getName().compareTo(o.getName());
    }

    /**
     * @param person
     *            the person to set
     */
    public void setPerson(final Person person) {
        this.person = person;
    }

    /**
     * @return the person
     */
    public Person getPerson() {
        return person;
    }

    public String getCode() {
        if (!StringUtils.isNullOrBlank(name))
            return name.split(" - ")[0];

        return "";
    }

    public String getSimpleName() {
        if (!StringUtils.isNullOrBlank(name)) {
            String[] parts = name.split(" - ");
            if (parts.length > 1)
                return parts[1];
        }

        return "";
    }
}
